package ui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.SwingUtilities;

public class BoardDisplay {

	private static BoardDisplay INSTANCE;
	private JDesktopPane desktopPane_ = null;
	
	private static int rightEdge_;
	private static int boxSize_, spaceWidth_, topLeftGo_;
	
	private static Dimension screen_;
	
	private BoardDisplay() {
		 screen_ = Toolkit.getDefaultToolkit().getScreenSize();
	}
	
	// Singleton method
	public static BoardDisplay getInstance() {
		if(INSTANCE == null) 
			INSTANCE = new BoardDisplay();
		
		return INSTANCE;
	}
	public void setRightEdge(int rightEdge) {
		rightEdge_ = rightEdge;
	}
	
	public void setBoxSize(int boxSize) {
		boxSize_ = boxSize;
	}
	
	public void setSpaceWidth(int spaceWidth) {
		spaceWidth_ = spaceWidth;
	}
	
	public void setTopLeftGo(int topLeftGo) {
		topLeftGo_ = topLeftGo;
	}
	
	public static int getRightEdge() {
		return rightEdge_;
	}
	
	public static int getBoxSize() {
		return boxSize_;
	}
	
	public static int getSpaceWidth() {
		return spaceWidth_;
	}
	
	public static int getTopLeftGo() {
		return topLeftGo_;
	}
	
	// Must be used by Frame to allow access to the DesktopPane
	public void setDesktopPane(JDesktopPane desktopPane) {
		desktopPane_ = desktopPane;
	}
	
	// Functions allows components to be added to the DesktopPane
	public void addComponent(JComponent component, Point location, Object layer) {
		component.setLocation(location);
		desktopPane_.add(component, layer);
	}
	
	public void addComponent(JComponent component, int pointX, int pointY, Object layer) {
		component.setLocation(pointX, pointY);
		desktopPane_.add(component, layer);
	}
	
	public void animateComponentLocation(final JComponent component, final int pointX, final int pointY) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				component.setLocation(pointX, pointY);
			}
		});
	}
	
	public void removeComponent(JComponent component) {
		desktopPane_.remove(component);
	}
	
	public static int getScreenHeight() {
		return screen_.height;
	}
	
	public static int getScreenWidth() {
		return screen_.width;
	}
	
	public FontMetrics getFontMetrics(Font font) {
		return desktopPane_.getFontMetrics(font);
	}
}
